{% load humanize %}

<div class="col-12 table-responsive">
    {# 계약자별 수납 리스트 #}
    <div class="row">
        <div class="col-sm"><h5><i class="dripicons-view-apps text-primary"></i> 계약자 데이터</h5></div>
        <div class="col-sm text-right mr-2">
            <span class="text-black-50 mr-3">총 계약 건수 : {{ contract_count }} 건</span>
            <a href="javascript:"
               onclick="alert('준비중입니다!')"
               class="ml-3 text-black-50">
                <i class="mdi mdi-file-excel-box"></i> Excel Export
                <i class="mdi mdi-download ml-1"></i>
            </a>
        </div>
    </div>


    <table id="scroll-horizontal-datatable"
           class="table table-hover table-centered table-condensed table-sm w-100 m-0 nowrap"
           style="word-break: keep-all;">
        <thead>
        <tr class="bg-nav-pills">
            <th scope="col">
                <label class="form-check-label" style="cursor: pointer;"><input type="checkbox" onclick="checkAll(this, 'chk[]')"> 전체</label>
            </th>
            <th class="text-center" scope="col">계약 일련번호</th>
            <th class="text-center" scope="col">차 수</th>
            <th class="text-center" scope="col">타 입</th>
            {% if this_project.is_unit_set %}
                <th class="text-center" scope="col">동호수</th>
            {% endif %}
            <th class="text-center" scope="col">계약자</th>
            <th class="text-center" scope="col">총 납입금</th>
            <th class="text-center" scope="col">현 회차상태(완납회차)</th>
            <th class="text-center" scope="col">계약일자</th>
        </tr>
        </thead>
        <tbody>
        {% for object in object_list %}
            {% with paid_amount=total_pay_by_contract.pop due_pay=amounts.pop %}
            <tr class="{% if object.contractorrelease.status == '3' %}bg-warning-lighten{% endif %}">
                <td scope="row">
                    <label class="form-check-label" {% if paid_amount < due_pay %}style="cursor: pointer;"{% endif %}>
                        <input type="checkbox" name="chk[]" value="{{ object.id }}" {% if paid_amount >= due_pay %}disabled{% endif %}> 선택
                    </label>
                </td>
                <td class="text-center" {% if object.status == '3' %}data-toggle="popover"
                    data-trigger="hover" title="" data-content="해지신청 상태" data-original-title=""{% endif %}>
                    [{{ object.contract.serial_number }}]
                </td>
                <td class="text-center">{{ object.contract.order_group }}</td>
                <td><i class="mdi mdi-square"
                       style="color: {{ object.contract.contractunit.unit_type.color }};"></i> {{ object.contract.contractunit.unit_type }}
                </td>
                {% if this_project.is_unit_set %}
                    <td class="text-center">{{ object.contract.contractunit.unitnumber }}</td>
                {% endif %}
                <td class="text-center" data-toggle="tooltip" data-placement="left" title="계약 등록 관리 [{{ object.name }}]"
                    {% if object.contractorrelease.status == '3' %}data-toggle="popover"
                    data-trigger="hover" title="" data-content="해지신청 상태" data-original-title=""{% endif %}>
                    <a href="{% url 'rebs:contract:register' %}?project={{ this_project.id }}&task=2&order_group={{ object.contract.order_group.id }}&type={{ object.contract.contractunit.unit_type.id }}&contract_unit={{ object.contract.contractunit.id }}&unit_number={{ object.contract.contractunit.unitnumber.id }}&cont_id={{ object.contract.id }}">
                        {{ object.name }}
                    </a>
                </td>
                <td class="text-right" data-toggle="tooltip" data-placement="right" title="건별 수납 관리 [{{ object.name }}]">
                    <a href="{% url 'rebs:cash-inout:payment-register' %}?project={{ this_project.id }}&type={{ object.contract.contractunit.unit_type.id }}&contract={{ object.contract.id }}">
                        {{ paid_amount|default:"-"|intcomma }}
                    </a>
                </td>
                    <td class="text-center">
                        {% if paid_amount >= due_pay %}<span class="text-success">완납 중</span>
                        {% else %}<span class="text-danger">미납 중</span>{% endif %}
                        ({{ paid_order.pop }})
                    </td>
                <td class="text-center">{{ object.contract_date|date:"Y-m-d" }}</td>
            </tr>
            {% endwith %}
        {% endfor %}
        </tbody>
    </table>
</div>
